<template>
	<view>
		<view>
			<uni-nav-bar shadow left-icon="left" dark title="新增报价" @clickLeft="back()" />
		</view>
		<view>
				<uni-card>
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">需求日期:</view>
						</uni-col>
						<uni-col :span="16">
								<uni-easyinput type="text" v-model="froms.needDate" disabled></uni-easyinput>
						</uni-col>
					</uni-row>
					
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;" >需求地址:</view>
						</uni-col>
						<uni-col :span="16">
								<uni-easyinput type="text" v-model="froms.address" disabled></uni-easyinput>
						</uni-col>
					</uni-row>
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">报价日期:</view>
						</uni-col>
						<uni-col :span="16">
						<uni-datetime-picker type="date" :clear-icon="false" v-model="QuotationItemForm.quoteDate" disabled />		
						</uni-col>
					</uni-row>
					
					
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">供货日期:</view>
						</uni-col>
						<uni-col :span="16">
							 <uni-datetime-picker type="date" :clear-icon="false" v-model="QuotationItemForm.supplyPeriod" />
						</uni-col>
					</uni-row>
					
					
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">货运方式:</view>
						</uni-col>
						<uni-col :span="16">
						        <uni-data-select
						          v-model="QuotationItemForm.deliveryMethod"
						          :localdata="range"
						        ></uni-data-select>
						</uni-col>
					</uni-row>
					
					
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">付款方式:</view>
						</uni-col>
						<uni-col :span="16">
								<uni-easyinput type="text" v-model="QuotationItemForm.deliveryPayment" placeholder="付款方式" disabled></uni-easyinput>
						</uni-col>
					</uni-row>
					
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">联系人:</view>
						</uni-col>
						<uni-col :span="16">
								<uni-easyinput type="text" v-model="froms.contactPerson" ></uni-easyinput>
						</uni-col>
					</uni-row>
					
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">联系方式:</view>
						</uni-col>
						<uni-col :span="16">
								<uni-easyinput type="text" v-model="froms.contactPhone" ></uni-easyinput>
						</uni-col>
					</uni-row>	
					<uni-row style="margin-top: 10rpx;">
						<uni-col :span="6">
								<view style="line-height:70rpx;font-size:30rpx;">备注:</view>
						</uni-col>
						<uni-col :span="16">
								<uni-easyinput type="text" v-model="QuotationItemForm.remark" ></uni-easyinput>
						</uni-col>
					</uni-row>
					
					<uni-row style="text-align: center;margin-top: 10rpx;">
						<uni-col :span="12"><button type="primary" size="mini" @click="add()">确定</button></uni-col>
						<uni-col :span="12"><button type="warn"    size="mini" @click="close()">关闭</button></uni-col>
					</uni-row>
					
					<view>
						<uni-segmented-control :current="current" :values="items" styleType="button" activeColor="#ffaa00" @clickItem="onClickItem" style="background-color: #fff"  />
					</view>
					
					<view v-if="current === 0">
						
						<uni-table border stripe >
							<uni-tr style="white-space: nowrap;text-align: center;font-size: 12rpx;">
								<uni-th align="center">物料编码</uni-th>
								<uni-th align="center">物料名称</uni-th>
								<uni-th align="center">物料规格</uni-th>
								<uni-th align="center">物料型号</uni-th>
								<uni-th align="center">单位</uni-th>
								<uni-th align="center">询价数量</uni-th>
								<uni-th align="center">预计单价(人民币:元)</uni-th>
								<uni-th align="center">预计金额(人民币:元)</uni-th>
								<uni-th align="center">报价单价(人民币:元)</uni-th>
								<uni-th align="center">报价金额(人民币:元)</uni-th>
							</uni-tr>
							<uni-tr v-for="(item,index) in table" :key="index" style="white-space: nowrap;text-align: center;font-size: 12rpx">
								<!-- <uni-td align="center"><uni-easyinput v-model="item.materialId"></uni-easyinput></uni-td> -->
								<uni-td align="center"><uni-easyinput v-model="item.materialcode" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.materialName" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.materialSpecifications" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.materialModel" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.meterage" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.quantity" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.unitPrice" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.sumPrice" disabled></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.offerUnitPrice"></uni-easyinput></uni-td>
								<uni-td align="center"><uni-easyinput v-model="item.offerSumPrice" disabled></uni-easyinput></uni-td>
							</uni-tr>
						</uni-table>
						
						
					</view>
					
				
					
					
				
					
				</uni-card>
			
		</view>
		
		
	</view>
</template>

<script>
	import {qtItemaddSave,oMDatatable} from "@/api/system/user"
	import { toast} from '@/utils/common'
	export default {
		data() {
			return {
			table:[],
			current:0,
			items: ['报价物料信息'],	
			range: [
				{"value": "公路运输","text": "公路运输"	},
				{"value":"集装箱运输","text": "集装箱运输"},
				{"value":"其他","text": "其他"},
				],	
			QuotationItemForm:{
			  inquiryId:null,
			  turn:null,//	
			  number:null,//
			  linkmanName:null,//
			  phone:null,//
			  quoteDate:null,
			  quantity:null,
			  unitPrice:null,
			  amount:null,
			  supplyPeriod:null,
			  deliveryAddress:null,
			  deliveryMethod:"公路运输",
			  deliveryPayment:"货到付款",
			  remark:null,
			  fixerName:null,
			  inquiryMaterialFormList:[],
			},	
			}
		},
		onLoad() {
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('acceptDataFromOpenerPage', (data) => {
			  this.froms = data.data
			 
			})
		
			this.QuotationItemForm.quoteDate=Date.now() - 2*24*3600*1000
	        
		oMDatatable({inquiryId:this.froms.rowId}).then(res=>{
	    
		this.table=res.rows
		for(let i=0;i<this.table.length;i++){
			this.table[i].offerSumPrice=this.table[i].sumPrice
		    this.table[i].offerUnitPrice=this.table[i].unitPrice
		}
			
			})
			
		},
		methods: {
				
			add(){
				this.QuotationItemForm.inquiryId=this.froms.rowId
				for(let i=0;i<this.table.length;i++){
					this.table[i].offerSumPrice=this.table[i].offerUnitPrice*this.table[i].quantity
				}
                this.QuotationItemForm.inquiryMaterialFormList=this.table
				qtItemaddSave(this.QuotationItemForm).then(res =>{
				alert("报价成功")
				this.$tab.reLaunch('/pages/work/supplier/supplier_inquiry_page')	
				})
			},
			
			close(){
				this.$tab.reLaunch('/pages/work/supplier/supplier_inquiry_page')
			},
			back(){
				this.$tab.reLaunch('/pages/work/supplier/supplier_inquiry_page')
			},
		}
	}
</script>

<style>

</style>
